/*
 * @Author: nccloud
 * @PageInfo: 新增
 */
import { UISTATUS ,AREA,BILLTYPECODE} from '../../constance';
import { buttonControl } from '../viewControl/buttonControl';
import { clearCardData, mainOrgInit } from '../utils/cardPageUtil';
import { ajax, toast, getBusinessInfo } from 'nc-lightapp-front';
import { STATUS } from '../../../../common/constant';
import { afterHeadEdit } from '../afterEvents/headAfterEvent';

export default function(props) {
        props.setUrlParam({ status: UISTATUS.add });
        clearCardData.call(this, props);
        buttonControl.call(this, props);
        mainOrgInit.call(this, props, this.contexts);
        let groupName = getBusinessInfo().groupName;
        let groupId = getBusinessInfo().groupId;
        let dbilldate = getBusinessInfo().businessDate;
        props.form.setFormItemsValue(AREA.cardHead, { ['dbilldate']: { value: dbilldate } });
        props.form.setFormItemsValue(AREA.cardHead, { ['pk_group']: { value: groupId ,display:groupName } }); 
        props.form.setFormItemsValue(AREA.cardHead, { ['billtype']: { value: BILLTYPECODE } });

        getLoginOrg(props, AREA.cardHead, 'pk_org');//自动获取登入组织

}

export function getLoginOrg(props, moduleId, key){

        ajax({
            url: '/nccloud/manualcostvo/common/getLoginOrgAction.do',
            data: [],
            success: (res) => {
                props.form.setFormItemsValue(moduleId, { [key]: res.data.org });

                if(res.data.hint != undefined){
                        toast(res.data.hint);
                }

                afterHeadEdit(props, moduleId, key);
            }
    })
}
